<template>
	<view :data-theme="themeStyle">
		<mescroll-uni @getData="getData" refs="mescroll" :size="10" v-if="addonIsExit.groupbuy">
			<block slot="list">
				<ns-adv keyword="NS_BARGAIN"></ns-adv>
				<!-- NS_BARGAIN -->
				<view class="bargain-page" v-if="dataList.length">
					<view class="bargain-list">
						<!-- <ns-goods-item-col :value="dataList" @toDetail="toDetail" type="groupbuy"></ns-goods-item-col> -->
						<!-- <view class="participation">
							<view class="bargin-item-title">
								—— &nbsp;砍价正在进行中&nbsp; ——
							</view>
							<view class="bargin-item">
								<image src="https://uniapp.saas.niuteam.cn//upload/471/common/images/20200521/20200521034017159004681781574_mid.jpg" mode="aspectFit"></image>
								<view class="content">
									<view class="title">休闲裤子女2019新款秋冬高腰格子小脚裤百搭韩版毛呢裤子女灯芯绒</view>
									<text class="residue-price ns-text-color">已砍至12.00元</text>
									<view class="operation">
										<view class="price-box">
											<text class="original-price">￥150</text>
											<view class="time">
												<text class="ns-bg-color">02</text>天
												<text class="ns-bg-color">02</text>:
												<text class="ns-bg-color">28</text>:
												<text class="ns-bg-color">28</text>
												后结束
											</view>
										</view>
										<button class="btn">正在砍价</button>
									</view>
									
								</view>
							</view>
						</view> -->
						<view class="no-participation">
							<view class="bargin-item-title ns-text-color">
								—— &nbsp;砍价商品&nbsp; ——
							</view>
							<view class="bargin-item" v-for="(dataItem,index) in dataList" :key="index">
								<image :src="$util.img(dataItem.sku_image,{ size: 'mid' })" mode="aspectFit" @error="imageError(index)"></image>
								<view class="content">
									<view class="title">{{dataItem.sku_name}}</view>
									<view class="operation">
										<view class="price-box">
											<text class="original-price">{{dataItem.price}}</text>
											<text>
												<block v-if="dataItem.floor_price == '0.00'">
													<text class="floor-price ns-text-color ns-font-size-lg">免费领取</text>
												</block>
												<block v-else>
													底价：<text class="floor-price ns-text-color ns-font-size-lg">{{ $lang('common.currencySymbol') }}{{dataItem.floor_price}}</text>
												</block>
											</text>
										</view>
										<button class="btn ns-bg-color" @click="toDetail(dataItem)">去砍价</button>
									</view>
									
								</view>
							</view>
						</view>
					</view>
				</view>
				<view v-if="!dataList.length" class="cart-empty"><ns-empty></ns-empty></view>
			</block>
		</mescroll-uni>
		<loading-cover ref="loadingCover"></loading-cover>
		<ns-show-toast></ns-show-toast>
	</view>
</template>

<script>
import uniTag from '@/components/uni-tag/uni-tag.vue';
import globalConfig from '@/common/js/golbalConfig.js';
import nsGoodsItemCol from '@/components/ns-goods-item/ns-goods-item-col.vue'
import nsShowToast from '@/components/ns-show-toast/ns-show-toast.vue'
export default {
	components: {
		uniTag,
		nsGoodsItemCol,
		nsShowToast
	},
	data() {
		return {
			dataList: []
		};
	},
	onShow() {
		// 刷新多语言
		if(!this.addonIsExit.groupbuy){
			this.$util.showToast({
				title:'商家未开启砍价',
				mask:true,
				duration:2000
			})
			setTimeout(()=>{
				this.$util.redirectTo('/pages/index/index/index',{},'redirectTo')
			},2000)
			return;
		}
		
		this.$langConfig.refresh();
	},
	mixins:[globalConfig],
	methods: {
		getData(mescroll) {
			this.$api.sendRequest({
				url: '/bargain/api/bargain/page',
				data: {
					page_size: mescroll.size,
					page: mescroll.num
				},
				success: res => {
					
					let newArr=[]
					let msg=res.message;
					
					if(res.code==0 && res.data){
						newArr = res.data.list;
					}else{
						this.$util.showToast({title:msg})
					}
					
					mescroll.endSuccess(newArr.length);
					
					//设置列表数据
					if (mescroll.num == 1) this.dataList = []; //如果是第一页需手动制空列表
					this.dataList = this.dataList.concat(newArr); //追加新数据
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
					
				},
				fail() {
					//联网失败的回调
					mescroll.endErr();
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				}
			});
		},
		toDetail(e) {
			this.$util.redirectTo('/promotionpages/bargain/detail/detail', {
				id: e.id
			});
		},
		imageError(index) {
			this.dataList[index].sku_image = this.$util.getDefaultImage().default_goods_img;
			this.$forceUpdate();
		}
	},
	onShareAppMessage(res) {
		var title = '砍价，优惠更多哦';
		var path = '/promotionpages/bargain/list/list';
		return {
			title: title,
			path: path,
			success: res => {},
			fail: res => {}
		};
	}
};
</script>
<style lang="scss">
	@import '../public/css/list.scss';
</style>
<style lang="scss" scoped>
/deep/ .fixed{position: relative;top:0}
/deep/ .empty {margin-top:0 !important}
.cart-empty{position:relative;top: -50%;padding-top: 54px;}
.pintuan-top {
	width: 100%;
	image {
		width: 100%;
	}
}
.empty {
	margin-top: 100rpx;
}
</style>
